// pages/find/exerciselist/exerciselist.js
const app = getApp()
var base_url = app.globalData.url
Page({

  /**
   * 页面的初始数据
   */
  data: {
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getStorage({
      key: 'student_id',
      success: function (res) {
        wx.request({
          url: base_url + '/getThisExercises/',
          method: 'POST',
          data: {
            student_id: res['data'],
          },
          header: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function (res) {
            console.log(res.data['exercises_lst'])
            if (res.data['exercises_lst'].length == 0){
              
              that.setData({
                ndisplay: "none",
                display: "block"
              })
            }else{
              that.setData({
                ndisplay: "block",
                display: "none",
                myExerciseList: res.data['exercises_lst']
              })
            }
            
          }
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  gotoDetail: function (e) {
    console.log(e.currentTarget.dataset.name)
    var data = e.currentTarget.dataset.name
    var status = data.split(',')[1]
    var uhid = data.split(',')[0]
    if (status == '未点评') {
      wx.showModal({
        title: '未点评',
        content: '当前作业未点评',
        success: function (res) {
          if (res.confirm) {
            console.log('弹框后点确定')
          } else {
            console.log('弹框后点取消')
          }
        }
      })
      return
    } else {
      wx.setStorage({
        key: 'uhid',
        data: uhid,
        success: function () {
        }
      })
      wx.navigateTo({
        url: '../thisExercise/thisExercise'
      })
    }

  }
})